package com.deepface.system.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.deepface.common.utils.DateUtils;
import com.deepface.common.utils.SecurityUtils;
import com.deepface.common.utils.file.FileTypeUtils;
import com.deepface.system.domain.SysFileInfo;
import com.deepface.system.service.SysFileInfoService;
import com.deepface.system.mapper.SysFileInfoMapper;
import javax.annotation.Resource;
import javax.xml.crypto.Data;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

/**
* @author 74707
* @description 针对表【sys_file_info(文件信息表)】的数据库操作Service实现
* @createDate 2023-12-15 11:28:07
*/
@Service
public class SysFileInfoServiceImpl extends ServiceImpl<SysFileInfoMapper, SysFileInfo>
    implements SysFileInfoService{

  @Resource
  SysFileInfoMapper sysFileInfoMapper;
  public int insertSysFileInfo(SysFileInfo sysFileInfo){
    sysFileInfo.setUserId(SecurityUtils.getUserId());
    sysFileInfo.setCreateBy(SecurityUtils.getUsername());
    sysFileInfo.setCreateTime(DateUtils.getNowDate());
    return sysFileInfoMapper.insert(sysFileInfo);
  }

  public int insertSysFileInfo(MultipartFile file,String jobInputDir,String fileNowName){
    String suffix = FileTypeUtils.getFileType(file.getOriginalFilename());
    SysFileInfo sysFileInfo = new SysFileInfo();
    sysFileInfo.setFileOriginName(file.getOriginalFilename());
    sysFileInfo.setFilePath(jobInputDir+fileNowName+"."+suffix);
    sysFileInfo.setFileNowName(fileNowName);
    sysFileInfo.setFileExt(suffix);
    return insertSysFileInfo(sysFileInfo);
  }

}




